package org.example.struct.array2;

import java.util.HashMap;
import java.util.Map;

/**
 * @author liyishan
 * @date 2023/10/19 13:18
 * @apiNote
 */

public class Test00873LenLongestFibSubseq {

    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6,7,8};
        System.out.println(test(arr));
    }

    public static int test(int[] arr) {
        Map<Integer,Integer> map = new HashMap<>();
        int n = arr.length;
        for (int i = 0; i < n; i++) {
            map.put(arr[i],i);
        }
        int[][] dp = new int[n][n];
        int ans = 0;
        for(int i = 0; i < n; i++){
            for(int j = i-1;j>=0 && arr[j]*2 > arr[i];j--){
                int k = map.getOrDefault(arr[i]-arr[j],-1);
                if(k>=0){
                    dp[j][i] = Math.max(dp[k][j]+1,3);
                }
                ans = Math.max(ans,dp[j][i]);
            }
        }
        return ans;
    }
}
